// pages/teacher/teacher.js
Page({
  data: {
    navbar: ['图书名称', '图书类别'],
    currentTab: 0
  },
  navbarTap: function (e) {
    //var that=this
    this.setData({
      currentTab: e.currentTarget.dataset.idx,
      //me:xdata
    })
    //将获取的查询的类别放入缓存中
    var teadep = e.currentTarget.dataset.name
    wx.setStorageSync("teadep", teadep);
  },
  //触发表发
  formSubmit(e) {
    //获取缓存的数据
    var teadep= wx.getStorageSync("teadep")
    if (teadep === '图书名称') {
      var bname = e.detail.value.bname;
      console.log(bname)
      //向后台发起请求，查询借阅图书的数据
      wx.request({
        url: 'http://localhost:8080/parking/book/bookinfo',//请求的地址
        data:{
          bname:bname//请求的参数
        },
        success:function(res){//请求成功返回的参数
          console.log(res.data.mess)
          wx.setStorageSync("info", res.data.mess)
          wx.navigateTo({
            url: '../../pages/book/book',
          })
        }
      })
    } else if (teadep === '图书类别') {
      var bkind = e.detail.value.bkind;
      console.log(bkind)
      wx.request({
        url: 'http://localhost:8080/parking/book/bookinfobkind',//请求的地址
        data: {
          bkind: bkind//请求的参数
        },
        success: function (res) {//请求成功返回的参数
          console.log(res.data.mess)
          wx.setStorageSync("info", res.data.mess)
          wx.navigateTo({
            url: '../../pages/book/book',
          })
        }
      })
    }
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // var xdata=wx.getStorageSync("key")
    // console.log('as',xdata)
    // var that=this
    // that.setData({
    //   me: xdata
    // })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      currentTab: e.currentTarget.dataset.idx,
      //me:xdata
    })
    var teadep = e.currentTarget.dataset.name
    console.log(teadep)
    if (teadep === '教室温度') {
      var that = this
      wx.request({
        url: 'http://localhost:8080/lg/sshlinuxController/requestdata',
        data: {
          com: "python wsss.py"
        },
        success: function (res) {
          var me = res.data.mess
          console.log(me)
          that.setData({
            me: me
          })
        },
      })
    } else if (teadep === '土壤湿度') {
      var that = this
      wx.request({
        url: 'http://localhost:8080/lg/sshlinuxController/requestdata',
        data: {
          com: "python trsd.py"
        },
        success: function (res) {
          var me = res.data.mess
          console.log(me)
          that.setData({
            me: me
          })
        },
      })
    }

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})